import Koa from 'koa';
import views from 'koa-views';
import bodyparser from 'koa-bodyparser';
import logger from 'koa-logger';
import staticFiles from 'koa-static-plus';
import config from './config/index.js';
import router from './router/index.js';
const app = new Koa();

// views
app.use(views('./views', {
  extension: 'ejs'
}))

// middlewares
app.use(bodyparser());
app.use(logger());

// 路由
app.use(router.routes());

//静态资源
app.use(staticFiles('./public',{
  pathPrefix: '/view'
}));

// 404
app.use(async ctx => {
  ctx.status = 404;
  await ctx.render("404");
});

app.listen(config.port, () => {
  console.log('--------server start--------');
})
